﻿//**********************************************************
//Copyright(C)2010 By 波特商网公司 版权所有。
//
//文件名：
//文件功能：用于将插件转换成菜单帮助类
//
//创建标识：齐李平 || 2011-04-06
//
//修改标识：
//修改描述：
//**********************************************************

using System;
using System.Drawing;
using System.Windows.Forms;
using Hmc.IM.Common.Plugin;
using Hmc.IM.Client.Properties;
using Hmc.IM.Common.UserControls;
using Hmc.IM.Common;

namespace Hmc.IM.Client.Core
{
    /// <summary>
    /// 插件转换成菜单帮助类
    /// </summary>
    public class PluginUIHelper
    {
        #region 模块菜单加载方法
        /// <summary>
        /// 初始化模块菜单UI
        /// </summary>
        /// <param name="plugin"></param>
        public static Panel InitMenuUI(IPlugin plugin)
        {
            //菜单背景Panel
            Panel tempPanel = new Panel();
            tempPanel.Width = 72;
            tempPanel.Height = 72;
            tempPanel.BackColor = Color.Transparent;
            tempPanel.Dock = DockStyle.Left;

            //菜单按钮
            PictureBox picture = new PictureBox();
            picture.BackColor = System.Drawing.Color.Transparent;
            picture.Image = plugin.ModulePicture;
            picture.InitialImage = null;
            picture.Dock = DockStyle.Left;
            picture.Size = new System.Drawing.Size(71, 71);
            picture.TabStop = false;
            picture.Cursor = Cursors.Hand;
            //将菜单添加到菜单背景Panel
            tempPanel.Controls.Add(picture);

            //添加菜单鼠标移进事件
            picture.MouseEnter += new EventHandler(picture_MouseEnter);
            //添加菜单鼠标移出事件
            picture.MouseLeave += new EventHandler(picture_MouseLeave);
            //添加菜单点击事件
            //picture.Click += new EventHandler(picture_Click);
            picture.Click += plugin.MenuClick;
            return tempPanel;
        }

        /// <summary>
        /// 菜单鼠标移进事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void picture_MouseEnter(object sender, EventArgs e)
        {
            PictureBox pictureBox = sender as PictureBox;
            Panel tempPanel = (Panel)pictureBox.Parent;
            tempPanel.BackgroundImage = Resources.nav_on;
        }

        /// <summary>
        /// 菜单鼠标移出事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void picture_MouseLeave(object sender, EventArgs e)
        {
            PictureBox pictureBox = sender as PictureBox;
            Panel tempPanel = (Panel)pictureBox.Parent;
            tempPanel.BackgroundImage = null;
        }
        #endregion

        /// <summary>
        /// 创建子菜单
        /// </summary>
        /// <param name="menuName">菜单名称</param>
        /// <param name="isChecked">是否选中</param>
        /// <param name="parentContainer">父容器</param
        /// <param name="clickEvent">点击事件</param>
        public static void CreateChildMenu(string menuName, bool isChecked, Control parentContainer, EventHandler clickEvent = null)
        {
            ucMenuButton menu = new ucMenuButton();
            menu.TagText = menuName;
            menu.Width = 80;
            menu.Height = 20;
            menu.IsChecked = isChecked;
            menu.Cursor = Cursors.Hand;
            if (isChecked) menu.TextColor = Color.FromArgb(4, 91, 196);
            menu.Margin = new System.Windows.Forms.Padding(2, 9, 0, 1);
            menu.BackColor = System.Drawing.Color.Transparent;
            if (clickEvent != null) menu.Click += clickEvent;
            parentContainer.Controls.Add(menu);
        }


    }
}
